<template>
  <div class="app-container">


    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="订单编号" prop="retailOrderId">
        <el-input v-model="queryParams.retailOrderId" placeholder="请输入订单编号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="项目名" prop="attName">
        <el-input v-model="queryParams.attName" placeholder="请输入项目名" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间" style="width: 308px">
        <el-date-picker v-model="daterangeCreateTime" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button icon="Refresh" @click="test">测试</el-button>
      </el-form-item>


    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['statistic:statistic:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cheackAttrlist">
      <el-table-column label="序号" type="index" />
      <el-table-column label="订单编号" align="center" prop="retailOrderId">
        <template #default="scope">
          <span>{{ scope.row.retailOrderId == 1 ? "合计" : scope.row.retailOrderId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目类型" align="center" prop="categoryId">
        <template #default="scope">
          <dict-tag :options="sys_exam_project" :value="scope.row.categoryId" />
        </template>
      </el-table-column>
      <el-table-column label="项目编码" align="center" prop="itemId" />
      <el-table-column label="项目名称" align="center" prop="attName" width="180" />
      <!-- <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
      <el-table-column label="数量" align="center" prop="attNum" />
      <!-- <template #default="scope">
            <dict-tag :options="order_toll_status" :value="scope.row.status"/>
          </template>
        </el-table-column> -->
      <!-- <el-table-column label="订单类型" align="center" prop="orderType">
          <template #default="scope">
            <dict-tag :options="order_type" :value="scope.row.orderType"/>
          </template>
        </el-table-column> -->
      <el-table-column label="成本单价(元)" align="center" prop="costPrice" />
      <el-table-column label="零售单价" align="center" prop="retailPrice" />
      <el-table-column label="成本总价" align="center" prop="costPriceAmount" />
      <el-table-column label="零售总价" align="center" prop="attPrice" />
      <el-table-column label="利润" align="center" prop="fitAmout" />
      <el-table-column label="订单日期" align="center" prop="createTime" />

    </el-table>
    <el-button type="primary" size="default" @click="test">测试按钮</el-button>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>
  
<script setup scope>
import { McslfAttrlist } from "@/api/statistic/checkattr";
import { listJob } from "../../../api/statistics/test"
const { proxy } = getCurrentInstance();
const {  sys_exam_project } = proxy.useDict('order_toll_status', 'order_type', 'sys_exam_project');
const cheackAttrlist = ref([
  {
    createTime: "2025-02-19 19:05:31",
    retailAttId: "f2f8b674c9d64c8eac7f0781525f5674",
    attId: 4,
    retailOrderId: 21,
    attPrice: 166.00,
    itemId: "1004",
    isInvoice: "1",
    categoryId: "3",
    attName: "精油开背",
    attNum: "1",
    costPrice: "50.00",
    retailPrice: null,
    costPriceAmount: "50.00",
    fitAmout: "116.00"
  }
]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const daterangeCreateTime = ref([]);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    retailOrderId: null,  // 项目编号
    attName: null       // 项目名
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询收费管理列表 */
function getList() {
  console.log(queryParams.value);
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangeCreateTime && '' != daterangeCreateTime) {
    queryParams.value.params["beginCreateTime"] = daterangeCreateTime.value[0];
    queryParams.value.params["endCreateTime"] = daterangeCreateTime.value[1];
  }
  McslfAttrlist(queryParams.value).then(response => {
    cheackAttrlist.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function test() {
  listJob()
}




// 表单重置
function reset() {
  form.value = {
    retailOrderId: null,
    prescriptionMedicineId: null,
    examinationId: null,
    shoudAmount: null,
    amount: null,
    createTime: null,
    status: null,
    orderType: null,
    patientAge: null,
    patientName: null,
    patientPhone: null,
    department: null,
    doctorName: null,
    payType: null,
    dockerId: null,
    patientId: null
  };
  proxy.resetForm("statisticRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeCreateTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}







/** 导出按钮操作 */
function handleExport() {
  proxy.download('statistic/statistic/export', {
    ...queryParams.value
  }, `statistic_${new Date().getTime()}.xlsx`)
}


getList();
</script>
  